<template>
		<el-select v-model="chooseOwner" value-key="" placeholder="选择品牌商" clearable filterable @change="sendOwner" style="margin-right:20px;">
			<el-option v-if="isTerrace"
				:label="'平台分类'"
				:value="''">
			</el-option>
			<el-option v-for="item in ownersList"
				:key="item.id"
				:label="item.name"
				:value="item.id">
			</el-option>
			
		</el-select>
		
</template>

<script>
import {GetBrandOwners} from '@/api/article.js'
export default {
 name:'brandOwner',
  data(){
	  return {
		  ownersList:[],
		  chooseOwner:''
	  }
  },
  props:{
	  initData:'',
	  allData: false,
	  isTerrace: {
		  type: Boolean,
		default:false
	  }
  },
  created(){
	this.ownersInit();
	console.log(this.initData);
	if(this.initData !==undefined){
		this.ownersList.push(this.initData);
		this.chooseOwner = this.initData.id;
	}
  },
  
  methods:{
	  async ownersInit(){
		  let params = {
			  PageIndex:1,
			  PageSize:100,
			  ShowPrivate:true,
		  }
		  const res = await GetBrandOwners(params);
		  console.log(res);
		  if(res.code== 200){
			  this.ownersList = res.data.list;
			  if(this.initData==undefined){
					this.chooseOwner = this.isTerrace?'':res.data.list[0].id;
				if(this.allData){
					this.$emit('sendOwner',this.ownersList[0]);
				}else{
					this.$emit('sendOwner',this.chooseOwner);
				}
			  }else{
				this.chooseOwner = this.initData.id;
			  }
		  }else{
			  this.ownersList = [];
		  }
	  },
	  sendOwner(){
		  if(this.allData){
			  let index = this.ownersList.findIndex(item=>item.id === this.chooseOwner)
				this.$emit('sendOwner',this.ownersList[index]);
			}else{
				this.$emit('sendOwner',this.chooseOwner)
			}
	  }
  }
}
</script>

<style>

</style>